package com.chanyachting.emall.action.member;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.chanyachting.emall.domain.Member;
import com.chanyachting.emall.form.MemberForm;
import com.chanyachting.emall.service.MemberService;
import com.chanyachting.emall.serviceImpl.MemberServiceImpl;
import com.chanyachting.emall.util.RequestUtil;

public class UpdateLinkEmail extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		
		MemberForm mform=(MemberForm)form;
		
		RequestUtil ru=new RequestUtil(request);
		
		Member member=(Member)ru.getSessionObject(MemberService.MEMBER_IN_SESSION,new Member());
		
		if(member.getEmail().equals(mform.getEmail())){
			
			if(!mform.getNewEmail().equals("") && mform.getNewEmail().equals(mform.getConfNewEmail())){
				
				MemberService memberService=new MemberServiceImpl();
				
				boolean temp=memberService.updateMemberEmail(mform.getNewEmail(), member);
				
				if(temp){
					
					member.setEmail(mform.getNewEmail());
					
					ru.setMsg("更新成功！");
					
				}else{
					
					ru.setMsg("更新失败！请稍候重试。");
				}
				
			}else{
				
				ru.setMsg("新邮件地址确认不一致！请确认新邮件地址。");
			}

		}else{
			
			ru.setMsg("旧邮件地址不正确！请确认邮件地址。");
		}
		
		
		
		return mapping.findForward("updateLinkEmail");
	}
	
	
	

}
